/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-07-28 21:06:54
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-11 17:52:44
 */
import 'package:flutter_data_center/model/user_model.dart';
import 'package:flutter_data_center/utills/sp_utils.dart';

class UserHelper {
  //私有化构造函数
  UserHelper._() {}

  //创建全局单例对象
  static UserHelper getInstance = UserHelper._();

  UserModel _userModel;

  //是否登录
  bool get isLogin => _userModel != null;

  set userModel(UserModel bean) {
    _userModel = bean;
    SPUtils.saveObject("userinfo", _userModel);
  }

  get userModel => _userModel;

  void init() {
    Map<String, dynamic> map = SPUtils.getObject("userinfo");
    if (map != null) {
      //加载缓存
      _userModel = UserModel.fromMap(map);
    }
  }

  void clear() {
    _userModel = null;
    SPUtils.remove("userinfo");
  }
}
